<!--
  Copyright 2020 The Chromium Authors. All rights reserved.
  Use of this source code is governed by a BSD-style license that can be
  found in the LICENSE file.
-->
<script type="module">
  const promisePreventDefault = Promise.reject(new Error('e'));
  window.onunhandledrejection = function(evt) {
    console.log('onunhandledrejection1');
    evt.preventDefault();
  };
  window.onrejectionhandled = function(evt) {
    console.log('onrejectionhandled1');

    setTimeout(runSecondPromiseRejection, 0);
  };

  setTimeout(() => {
    promisePreventDefault.then(function(){}, function(){});
  }, 10);

  function runSecondPromiseRejection() {
    const rejectedPromise = Promise.reject(new Error('e'));
    window.onunhandledrejection = function(evt) {
      console.log('onunhandledrejection2');

      setTimeout(() => {
        rejectedPromise.then(function(){}, function(){});
      }, 10)
    };
    window.onrejectionhandled = function(evt) {
      console.log('onrejectionhandled2');
    };
  }
</script>
